package com.jabo.douban.demo.presentation.view.adapter;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

/**
 * @anthor JZheng3
 * @Time: 2020/2/28
 */
public class HomeFragmentPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> mFragments;

    public HomeFragmentPagerAdapter(@NonNull FragmentManager fm, List<Fragment> fragments) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        mFragments = new ArrayList<>();
        mFragments.addAll(fragments);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }

    @Override
    public int getCount() {
        return mFragments.size();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        String[] titles = new String[]{"关注", "推荐"};
        return titles[position];
    }
}
